<?php

namespace App\Service\CallingCards;

use App\Models\Common\ConfigModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;

class ConfigService
{
    public static function areaRobots(): array
    {
        $cacheKey = 'tiger_calling_cards_area_robots';
        $body     = Cache::get($cacheKey);
        if (null === $body) {
            $body = [];
            $json = ConfigModel::query()
                ->where('module', 'callingCards')
                ->where('name', 'areaRobots')
                ->value('value');
            if (is_string($json)) {
                foreach (json_decode($json, true) ?? [] as $k => $v) {
                    $body[$k] = $v;
                }
            }
            Cache::put($cacheKey, $body, now()->addMinute());
        }
        return $body;
    }
}
